'use strict';

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    baseController = require('../../../Base/server/controllers/BaseDoc.js');

//条码流水
var newModel = baseController.getBaseDocFields();
//条码主档
newModel.BarcodeMaster = {
    type: Schema.ObjectId,
    ref: 'BarcodeMaster'
};
//采集时间
newModel.CollectDateTime = {
    type: Date,
    default: Date.now
};
//终端
newModel.Terminal = {
    type: Schema.ObjectId,
    ref: 'Terminal'
};
//终端名称
newModel.TerminalName = {
    type: String,
    trim: true
};
//工序
newModel.Operation = {
    type: Schema.ObjectId,
    ref: 'Operation'
};
//工序名称
newModel.OperationName = {
    type: String,
    trim: true
};
//作业
newModel.Work = {
    type: Schema.ObjectId,
    ref: 'Work'
};
//作业名称
newModel.WorkName = {
    type: String,
    trim: true
};
//工位
newModel.WorkLocation = {
    type: Schema.ObjectId,
    ref: 'WorkLocation'
};
//工位名称
newModel.WorkLocationName = {
    type: String,
    trim: true
};
//用户集合
newModel.Users = {
    type: [
        {
            type: Schema.ObjectId,
            ref: 'User'
        }
    ]
};
//业务状态 0: 开始 1: 完成
newModel.BusinessStatus = {
    type: Number
};
//质检类型 0: 全检 1:巡检 2:首件质检
newModel.QCType = {
    type: Number
};
//质检状态 0: 合格 1:不合格 2:让步接收 3:品质判定 4:返工 5:报废
newModel.QCStatus = {
    type: Number
};
//质检人，首件质检用
newModel.QCUser = {
    type: Schema.ObjectId,
    ref: 'User'
};
//质检时间，首件质检用
newModel.QCDateTime = {
    type: Date
};
//备注
newModel.Remark = {
    type: String,
    trim: true
};

var newSchema = new Schema(newModel);
newSchema.index({BarcodeMaster: 1, CollectDateTime: 1}, {"unique": true});
newSchema.index({BarcodeMaster: 1});

mongoose.model('BizRecord', newSchema, 'BizRecord');
